package com.primeton.fickviewtest;

import com.espertech.esper.client.Configuration;
import com.espertech.esper.client.EPServiceProvider;
import com.espertech.esper.client.EPServiceProviderManager;
import com.espertech.esper.client.EPStatement;

public class MainClass {
	public static void main(String[] args) {
		Configuration config = new Configuration();
		config.getEngineDefaults().getThreading().setInternalTimerEnabled(false); // external
																																							// timer
																																							// for
																																							// testing
		config.addEventType("CountEvent", CountEvent.class);
		config.addPlugInView("countview", "countViewDay", CountViewFactory.class.getName());

		EPServiceProvider epService = EPServiceProviderManager.getProvider("countView", config);
		epService.initialize(); // Since running in a unit test may use the same
														// engine many times

		Object[][] statements = new Object[][] { { "countView", "select * from CountEvent.countview:countViewDay(11, 0)" }, };

		for (Object[] statement : statements) {
			String stmtName = (String) statement[0];
			String expression = (String) statement[1];
			System.out.println("Creating statement: " + expression);
			EPStatement stmt = epService.getEPAdministrator().createEPL(expression, stmtName);

			if (stmtName.equals("countView")) {
				CountUpdateListener listener = new CountUpdateListener();
				stmt.addListener(listener);
			}
		}
		CountEvent event1 = new CountEvent("test1", 23D, 24D);
		CountEvent event2 = new CountEvent("test2", 21D, 24D);
		CountEvent event3 = new CountEvent("test3", 223D, 24D);
		CountEvent event4 = new CountEvent("test4", 233D, 24D);
		CountEvent event5 = new CountEvent("test5", 243D, 24D);
		CountEvent event6 = new CountEvent("test6", 253D, 24D);
		CountEvent event7 = new CountEvent("test7", 236D, 24D);
		CountEvent event8 = new CountEvent("test8", 273D, 24D);
		CountEvent event9 = new CountEvent("test9", 283D, 24D);
		CountEvent event11 = new CountEvent("test11", 238D, 24D);
		epService.getEPRuntime().sendEvent(event11);
		epService.getEPRuntime().sendEvent(event1);
		epService.getEPRuntime().sendEvent(event2);
		epService.getEPRuntime().sendEvent(event3);
		epService.getEPRuntime().sendEvent(event4);
		epService.getEPRuntime().sendEvent(event5);
		epService.getEPRuntime().sendEvent(event6);
		epService.getEPRuntime().sendEvent(event7);
		epService.getEPRuntime().sendEvent(event8);
		epService.getEPRuntime().sendEvent(event9);
	}
}
